package com.prs.crm.service.doc.impl;

import java.util.Collection;
import java.util.Date;

import com.prs.crm.context.ToolKits;
import com.prs.crm.dao.doc.IssueLeaveDao;
import com.prs.crm.domain.doc.IssueLeave;
import com.prs.crm.domain.hr.Leave;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.service.doc.IssueLeaveService;
import com.prs.crm.service.hr.LeaveService;
import com.prs.crm.service.hr.PersonService;
import com.prs.crm.service.impl.BaseServiceImpl;

public class IssueLeaveServiceImpl extends BaseServiceImpl<IssueLeave,IssueLeaveDao> implements IssueLeaveService{
	private PersonService personService;
	private LeaveService leaveService;
	
	@Override
	public void submitIssueLeave(Date issueStartTime, Date issueEndTime,
			String issueDocIds, String receivePersons) {
		// TODO Auto-generated method stub
		Collection<Person> receivePerson = this.getPersonService().findPersons(ToolKits.convertStringAryToIntAry(receivePersons.split(",")));
		Collection<Leave> leaves = leaveService.getLeaveByIds(ToolKits.convertStringAryToIntAry(issueDocIds, ","));
		for(Leave leave:leaves) {
			for(Person person : receivePerson) {
				IssueLeave issue = new IssueLeave();
				issue.setLeave(leave);
				issue.setRecorder(person);
				issue.setReceivePerson(person);
				issue.setStartTime(issueStartTime);
				issue.setEndTime(issueEndTime);
				this.getDao().save(issue);
			}
		}
	}

	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public PersonService getPersonService() {
		return personService;
	}

	public void setLeaveService(LeaveService leaveService) {
		this.leaveService = leaveService;
	}

	public LeaveService getLeaveService() {
		return leaveService;
	}

	@Override
	public Collection<IssueLeave> getValidIssueLeave(Person person) {
		// TODO Auto-generated method stub
		return this.getDao().getValidIssueLeave(person);
	}

}
